import tkinter as tk
import tensorflow as tf

# 创建Tkinter窗口
root = tk.Tk()
root.geometry("300x600")
root.title("TensorFlow操作示例")

# 创建两个张量
A = tf.constant([[1, 2], [3, 4], [5, 6]])
B = tf.constant([[1, -1], [2, -2], [3, -3]])

# 函数：执行TensorFlow操作并更新GUI
def perform_operations():
    global A, B
    # 张量相加
    add = tf.add(A, B)
    # 张量相减
    sub = tf.subtract(A, B)
    # 张量相乘
    mul = tf.multiply(A, B)
    # 张量相除
    div = tf.divide(A, B)
    
    result_text = f"张量A：\n{A.numpy()}\n\n张量B：\n{B.numpy()}\n\n相加：\n{add.numpy()}\n\n相减：\n{sub.numpy()}\n\n相乘：\n{mul.numpy()}\n\n相除：\n{div.numpy()}"
    result_label.config(text=result_text)

# 创建按钮来执行操作
button = tk.Button(root, text="执行操作", command=perform_operations)
button.pack(pady=10)

# 创建标签来显示结果
result_label = tk.Label(root, text="", justify="left")
result_label.pack(pady=10)

# 运行Tkinter主循环
root.mainloop()